// ==UserScript==
// @name           Shacknews Name Color Friend Foe
// @namespace      http://troz.shackspace.com
// @description    Colors user account names for shacknews.com comments system.
// @include        http://*.shacknews.com/laryn.x?*
// @include        http://shacknews.com/laryn.x?*
// @include        http://shacknews.com/settings/
// @include        http://*.shacknews.com/settings/

// ==/UserScript==
/*

Thanks to Tissen for the idea and inspiration to implement a beter method for coloring the usernames
Thanks to ThomW for the borrowed code and mach assistance and for comments and suggestions to improve the script. 

Version history:
1.0  2008-2-27:
Name coloring
Employee/Mod highlighting
Friend/Foe list
Self Highlighting
Menu for friend/foe changes, and usefull links.

1.1 2008-2-29:
Bugfix for bad SM/comment history links
Added Shackspace link for mercury users with lightning bolt enabled
Added Thread Starter Highlighting (thanks for suggestion DrWaffles!)

1.2 2008-5-30
Fix for new profile links.

1.3 2009-1-20
Updated to work beter with anthonybean's inline profile info script.

1.AWESOME 2009-12-21
r{b[* S H A C K S C R I P T S ' D *]b}r
Also updated the employees and mods arrays.

//add icon next to name
style="padding: 0px 20px 0px 0px; background-repeat: no-repeat; background-position: top right; background-image: url();"
*/

if (script_enabled('friendfoe') == "true") {



var employees = new Array(
	"4"				, // Steve Gibson
	"43653" 	, // Maarten Goldstein
	"175043"	, // Chris Faylor
	"175046"	, // Nick Breckon
	"188134"	, // Aaron Linde
	"44124"		, // sHugamom
	"204735"  , // Alice O'Connor
	"212323"		// Garnett Lee
);

var mods = new Array(
	"3259"  ,	// degenerate
	"10028" , // drucifer
	"168479", // ajax
	"5334"  , // dante
	"7438"  , // enigmatic
	"169489", // s[genjuro]s
	"8105"  , // hirez
	"5278"  ,	// lacker
	"6674"  , // pupismyname
	"32016" , // thekidd
	"1194"  , // zakk
	"171402", // brickmatt
	"6585"  , // carnivac
	"168256", // edgewise
	"169197", // filtersweep
	"9980"  , // haiku
	"44583" , // jokemon
	"3243"  , // p[multisync]p
	"169049", // rauol duke
	"8349"  , // sexninja!!!!
	"194196",	// ninjase
	"6933"  , // tomservo
	"9085"  , // busdriver3030
	"8048"  , // cygnus x-1
	"6380"  , // dognose
	"167953", // edlin
	"12398" , // geedeck
	"171127", // helvetica
	"7570"  , // kaiser
	"8316"  , // paranoid android
	"9031"  , // portax
	"9211"  , // redfive
	"7660"  , // sexpansion pack
	"169927", // sgtsanity
	"15130"   // utilitymaximizer
);

var fabulous = '168102,28220,3243'//polansk,korban,multisync
var celeb = '';
var greasemonkeydev = '5317,173455,172676,6317,171082,4245,2536,161569,182981,177008';//From Dodob's profile: ThomW,MisterPhoton,naabster,dodob,Pieman,Tissen,Troz,ieGod,OverloadUT,arhughes
var kickassnogum = '6380';//dognose
//game developer is from sharkii's profile
var gamedeveloper = '4957,171370,'+//2k Games   jason bergman,  dahanese
	'182981,'+//2K Sports OverloadUT
	'168928,13098,7048,171248,169937,173984,'+//3D Realms  eskimo spy, georgeb3dr - George Broussard, Joe3DR - Joe Siegler, Mr. 9000 - John Schuch, Scatti, ScottMi11er - Scott Miller
	'169686,'+//Airtight Games  Dravalen
	'119968,'+//Affectworks  fredrik s
	'32598,'+//Artificial Mind & Movement  derean
	'4929,'+//Atari (Dallas)  YoYo
	'174434,170554,'+//Bethesda Softworks  lplasmatron, speon
	'8085,'+//Bioware  Derek French
	'168742,'+//Bungie  dmiller - Dan Miller
	'14633,'+//Buzz Monkey Software  Karnov
	'170764,12418,'+//Digital Illusions CE (dice) (Sweden)   aavenr, -efx-
	'270,'+//EA Canada (PSP)   timmie
	'4312,170275,'+//Epic   CliffyB - Cliff Bleszinski, fufux
	'175192,'+//Free Radical Design  jbury
	'186653,'+//Flagship Studios  Ivan Sulic
	'7466,173003,172749,'+//GarageGames  d3tached - (Torque X), sullisnack - Sean Sullivan, timaste - Tim Aste
	'4605,'+//Gas Powered Games  hellchick - Caryn Law
	'3829,169955,171337,6020,168552,172976,166528,4178,'+//Gearbox Software  rickmus, byorn, DaMojo - Pat Krefting, duvalmagic - Randy Pitchford, kungfusquirrel, MADMikeDavis, mikeyzilla - Mike Neumann, wieder - Charlie Wiederhold
	'172526,'+//hb-studios  threeup
	'171752,19054,'+//Human Head  lvlmaster, zeroprey
	'170311,3982,4916,'+//Id Software  patd - Patrick Duffy, toddh - Todd Hollenshead, xian - Christian Antkow
	'102,21915,119746,'+//Infinity Ward  Avatar, DKo5, Inherent
	'169079,'+//Massive Entertainment  SilverSnake
	'12865,'+//Monolith  cannelbrae
	'183170,172349,'+//Naughty Dog  Cowbs (previously known as cpnkegel)
	'1347,'+//NCSoft  Zoid - Dave Kirsch
	'12631,'+//Nerve Software  Normality - Joel Martin
	'12963,6507,27483,169925,11816,4257,'+//Pandemic Studios  darweidu, Freshview, gndagger, Rampancy, sammyl, tostador
	'170163,'+//Piranha Games  Buckyfg1
	'4262,'+//Planet Moon  cheshirecat
	'14033,'+//Remedy Entertainment  PetriRMD - Petri Jarvilehto(?)
	'8202,2025,'+//Retro Studios  Andy Hanson - Andy Hanson, Jack Mathews - Jack Mathews
	'169919,'+//Rockstar Games  bozer
	'169712,'+//S2 Games  s2jason - Jason
	'171285,'+//Slant Six  bakanoodle
	'171466,'+//Stardock  mittense
	'173743,'+//Stray Bullet Games  AshenTemper - Sean Dahlberg
	'172702,13334,169942,'+//TellTale Games  dtabacco, jake2000 - Jake Rodkin, mikecyb
	'173748,'+//ThreeWave Software  brome - Adam Bromell
	'172581,'+//Treyarch  Krypt_ - Brian Glines
	'6358,'+//Trauma Studios  Ease_One
	'171762,168242,'+//UbiSoft  mnok, MrLobo
	'173884,12149,125906,173374,190115,'+//Valve  Doug_Support - Doug Valente (Support), Erik Johnson - Erik Johnson, garymct - Gary McTaggart, locash - Patrick M (Support), RobinWalker
	'170414,9172,'+//Vivendi Universal  ColoradoCNC, Pezman
	'12656,'+//Zemnott  KnyteHawkk - Jared Larsen
	'49660,169993,174785'//Former Game Indusrty People     Omning, robingchyo, Romsteady

var colorNames = 		GM_getValue("colorNames","true");
var highlightSelf = 	GM_getValue("highlightSelf","true");
var showEmployees = 	GM_getValue("showEmployees","true");
var showMods = 			GM_getValue("showMods","true");
var showFriendFoe = 	GM_getValue("showFriendFoe","true");
var showImages = 		GM_getValue("showImages","true");
var menuMouseOver = 	GM_getValue("menuMouseOver","false");
var hlThreadStarter = 	GM_getValue("hlThreadStarter","true");

var friendcss = 		GM_getValue("friendcss",		"background-color: #004000 !important; border: 1px solid #40ff40 !important;");
var foecss = 			GM_getValue("foecss",			"background-color: #600000 !important; border: 1px solid #ff4040 !important;");
var other1css = 		GM_getValue("other1css",		"background-color: #000080 !important; border: 1px solid #6060ff !important;");
var other2css = 		GM_getValue("other2css",		"background-color: #600060 !important; border: 1px solid #ff40ff !important;");
var employeecss = 		GM_getValue("employeecss",		"text-decoration: overline underline !important;");
var modcss = 			GM_getValue("modcss",			"border-top: 1px dotted !important; border-bottom: 1px dotted !important;");
var highlightcss = 		GM_getValue("highlightcss",		"border: 2px solid white !important;");
var threadstartercss = 	GM_getValue("threadstartercss",	"background-color: #303030 !important; font-size: 125% !important; ");

var image = new Array(16);
//hey!
image[0] = 'padding: 0px 5px 0px 5px; background-image: url() !important; color: black !important;';
//alien
image[1] = 'padding: 0px 20px 0px 0px; background-repeat: no-repeat !important; background-position: top right !important; background-image: url() !important;';
//beer
image[2] = 'padding: 0px 20px 0px 0px; background-repeat: no-repeat !important; background-position: top right !important; background-image: url() !important;';
//ghost
image[3] = 'padding: 0px 20px 0px 0px; background-repeat: no-repeat !important; background-position: top right !important; background-image: url() !important;';
//heart
image[4] = 'padding: 0px 20px 0px 0px; background-repeat: no-repeat !important; background-position: top right !important; background-image: url() !important;';
//mushroom
image[5] = 'padding: 0px 20px 0px 0px; background-repeat: no-repeat !important; background-position: top right !important; background-image: url() !important;';
//smiley
image[6] = 'padding: 0px 20px 0px 0px; background-repeat: no-repeat !important; background-position: top right !important; background-image: url() !important;';

//frowny
image[7] = 'padding: 0px 20px 0px 0px; background-repeat: no-repeat !important; background-position: top right !important; background-image: url() !important;';
//poop
image[8] = 'padding: 0px 20px 0px 0px; background-repeat: no-repeat !important; background-position: top right !important; background-image: url() !important;';
//star
image[9] = 'padding: 0px 20px 0px 0px; background-repeat: no-repeat !important; background-position: top right !important; background-image: url() !important;';
//joystick
image[10] = 'padding: 0px 20px 0px 0px; background-repeat: no-repeat !important; background-position: top right !important; background-image: url() !important;';
//duke
image[11] = 'padding: 0px 20px 0px 0px; background-repeat: no-repeat !important; background-position: top right !important; background-image: url() !important;';
//greasemonkey
image[12] = 'padding: 0px 20px 0px 0px; background-repeat: no-repeat !important; background-position: top right !important; background-image: url() !important;';
//360
image[13] = 'padding: 0px 20px 0px 0px; background-repeat: no-repeat !important; background-position: top right !important; background-image: url() !important;';
//ps3
image[14] = 'padding: 0px 20px 0px 0px; background-repeat: no-repeat !important; background-position: top right !important; background-image: url() !important;';
//wii
image[15] = 'padding: 0px 20px 0px 0px; background-repeat: no-repeat !important; background-position: top right !important; background-image: url() !important;';


/* UTILITY FUNCTIONS */
var benchmarkTimer = null;
function getTime() { benchmarkTimer = new Date(); return benchmarkTimer.getTime(); }
var scriptStartTime = getTime();
function saveSettingCheck() {
GM_log('SaveSettingCheck '+this.id.split('_')[1]+' - '+this.checked);
	GM_setValue(this.id.split('_')[1], this.checked);
}
function saveSettingValue() {
	GM_setValue(this.id.split('_')[1], this.value);
}
function addBackground(list,id,name){
//GM_log("addBackground("+list+","+id+","+name+")");
	removeBackground(id,null);
	var names = GM_getValue(list,'');
	if(names.length>0){
		names += ','+id;
	}else{
		names = ''+id;
	}
	GM_setValue(list,names);
	if(name!=null){
		alert('Added '+name+' to '+list+' list.');
	}	
}
function removeBackground(id,name){
	GM_setValue('foes',remove(GM_getValue('foes',''),id));
	GM_setValue('friends',remove(GM_getValue('friends',''),id));
	GM_setValue('other1',remove(GM_getValue('other1',''),id));
	GM_setValue('other2',remove(GM_getValue('other2',''),id));
	if(name!=null){
		alert('Removed '+name+' from friend, foe and other lists.');
	}
}
function addImage(list,id,name){
//GM_log("addimage  list="+list);
	removeImage(id,null);
	if(list!=null){
		list=list.split('_');
		if(list.length==2){
			list=list[1];
		}else{
			return;
		}
	}else{
		return;
	}
	var names = GM_getValue(list,'');
	if(names.length>0){
		names += ','+id;
	}else{
		names = ''+id;
	}
	GM_setValue(list,names);
	if(name!=null){
		alert('Added '+name+' to '+list+' list.');
	}	
}
function removeImage(id,name){
	for(var i=0;i<image.length;i++){
		GM_setValue('image'+i,remove(GM_getValue('image'+i,''),id));
	}
	if(name!=null){
		alert('Removed image from '+name+'.');
	}
}
function remove(list,id){
	var arr=list.split(',');//turn string list into array of numbers
	var pos = arr.indexOf(id);//find the position of id in the array
	if(pos > -1){//if it exists
		arr.splice(pos,1);//remove the item at position pos
		list = arr.toString();//turn the array back into a string
	}
	return list;
}
function hide(e){
	if(e.target.parentNode == document.body){
		document.body.removeChild(e.target);
	}
}
function clickListener(e){
	//GM_log('click listener  event='+e);
	var elm = e.target;
	//GM_log('click listener  tag = '+elm);
	//GM_log('click listener  tag name = '+elm.tagName);
//	var isString = elm instanceof String;
	//GM_log('click listener  isString = '+isString);
	if( elm.tagName=='a' || elm.tagName=='A'){
		var url = elm.getAttribute('href');
		if(url==null){
			return;
		}
		//GM_log('click listener  url = '+url);
		if(url.indexOf('profile.x?person=')>0 || url.indexOf('profile/')>0){
			//GM_log('click listener  foReals = '+elm.getAttribute('foReals'));
			if(elm.getAttribute('foReals')<1){
				//GM_log('click listener   in popup');
				//ok, user clicked on a profile page link, that wasn't one the we made, so intercept it and show a popup
				
				//if an old menu exists, remove it
				var old = document.getElementById('shackfriendfoe_menu');
				if(old != null){
					document.body.removeChild(old);
				}
				
				var name = elm.innerHTML.replace(/^\s+|\s+$/g, ''); // Trim spaces at both ends.;
				
				var id = '';
				var parent = elm.parentNode;
				//GM_log('click listener   parent = '+parent);
				if(parent==null){
					return;
				}
				var parentclass = parent.getAttribute('class');
				//GM_log('click listener   parent.class = '+parentclass);
				if(parentclass=='author'){
					//this is a full post, need to go up 2 more levels
					parent=parent.parentNode;
					if(parent!=null){
						parent=parent.parentNode;
						if(parent==null){
							return;
						}else{
							parentclass = parent.getAttribute('class');
						}
					}else{
						return;
					}
				}
				//GM_log('click listener   parent.class = '+parentclass);
				var regex = /.*author_(\d+).*/
				matches = (parentclass).match(regex);
				//GM_log('click listener   num matches = '+matches.length );
				if(matches.length != 2){
					//GM_log('click listener   no class matches');
					return; 
				}
				//GM_log('click listener   match = '+matches[1]);
				id = matches[1];
				
				var isMercury = false;
				var sibling = elm.nextSibling;				
				while(sibling!=null && sibling.nodeType!=1){//1 is an element - apparently the next node is usually a text node with a newline or spaces because the elements are not immediatly next to each other in the source, but have a newline and tabbing between them.
					sibling = sibling.nextSibling;
				}
				if(sibling!=null && sibling.getAttribute('class')=="lightningbolt"){
					isMercury=true;
				}
				
				var encodedName;
				if(url.indexOf('profile/')>0){
					encodedName	= url.substr(url.indexOf('profile/')+8);
				}else{
					encodedName	= url.substr(url.indexOf('=')+1);
				}
				
				var str='<div class="olauthor_'+id+'"><a class="oneline_user" href="'+elm.href+'" foReals="1">'+name+'</a></div>';//name line
				str+='<div><a href="'+elm.href+'" foReals="2" name="profiled">Profile</a></div>';//profile
				str+='<div><a href="/msgcenter/new_message.x?to='+encodedName+'">Message User</a></div>';//Message User
				str+='<div><a href="/search.x?type=comments&terms=&cs_user='+encodedName+'">Comment History</a></div>'//comment search
				str+='<div><a href="'+(elm.href).replace('profile','library')+'">Game Library</a></div>'//Game Library
				if(isMercury == true){
					str+='<div><a href="http://'+(name.replace(/ /g,'_'))+'.shackspace.com">Shackspace</a></div>'//Shackspace
				}
				if(showFriendFoe == "true"){
					str+='<div><a id="shackfriendfoe_friends" style="'+friendcss+'; cursor: pointer;">Friend</a>';//friend
					str+='|<a id="shackfriendfoe_foes" style="'+foecss+'; cursor: pointer;">Foe</a>';//foe
					str+='|<a id="shackfriendfoe_other1" style="'+other1css+'; cursor: pointer;">Other1</a>';//other1
					str+='|<a id="shackfriendfoe_other2" style="'+other2css+'; cursor: pointer;">Other2</a>';//other2
					str+='|<a id="shackfriendfoe_meh" style="cursor: pointer;">None</a></div>';//meh
				}
				if(showImages == "true"){
					str+='<div>'
					for(var i=0;i<image.length;i++){
						str+='<a id="shackfriendfoe_image'+i+'" style="cursor: pointer;'+image[i]+'">&nbsp;</a>';
						if(i==8)
							str+='</div><div>'
					}
					str+='&nbsp; &nbsp; <a id="shackfriendfoe_imageremove" >No Img</a></div>';
				}
				
				//GM_log('click listener   html = '+str);
				var x = -5;
				var y = -5;
				var theElement = elm;
				while(theElement != null){
				    x += theElement.offsetLeft;
				    y += theElement.offsetTop;
				    theElement = theElement.offsetParent;
				  }
				
				var nnode = document.createElement("div");
				var style = 'position: absolute; top: '+y+'px; left: '+x+'px; border: 2px solid #F02E01; background: black; padding: 5px;';
				//GM_log('click listener   style = '+style);
				nnode.setAttribute('style',style);
				nnode.setAttribute('id','shackfriendfoe_menu');
				nnode.setAttribute('class','oneline oneline0');//one of these gets the coloring/hightlighting I want.
				nnode.addEventListener('mouseout',hide,true);
				nnode.innerHTML = str;
				document.body.appendChild(nnode);
				
				//add friend / foe events
				var ffnode = document.getElementById('shackfriendfoe_friends');
				if(ffnode!=null) ffnode.addEventListener( 'click', function(){ addBackground('friends',id,name); },true);
				ffnode = document.getElementById('shackfriendfoe_foes');
				if(ffnode!=null) ffnode.addEventListener( 'click', function(){ addBackground('foes',id,name); },true);
				ffnode = document.getElementById('shackfriendfoe_other1');
				if(ffnode!=null) ffnode.addEventListener( 'click', function(){ addBackground('other1',id,name); },true);
				ffnode = document.getElementById('shackfriendfoe_other2');
				if(ffnode!=null) ffnode.addEventListener( 'click', function(){ addBackground('other2',id,name); },true);
				ffnode = document.getElementById('shackfriendfoe_meh');
				if(ffnode!=null) ffnode.addEventListener( 'click', function(){ removeBackground(id,name); },true);
				ffnode = document.getElementById('shackfriendfoe_imageremove');
				if(ffnode!=null) ffnode.addEventListener( 'click', function(){ removeImage(id,name); },true);
				for(var i=0;i<image.length;i++){
					ffnode = document.getElementById('shackfriendfoe_image'+i);
					if(ffnode!=null) ffnode.addEventListener( 'click', function(e){ addImage(e.target.getAttribute('id'),id,name); },true);
				}
				
				//GM_log('click listener   done');
				
				if(menuMouseOver == "false"){
					e.preventDefault();
					e.stopPropagation();
				}
			}
		}
	}
}

var count=0;
if((document.location).toString().indexOf('laryn.x')>-1){
	//comments page - color the names

	var css='';
	var color;
	var r;
	var g;
	var b;
	
	

	if(colorNames == "true" || hlThreadStarter == "true"){
	
		var friends = GM_getValue('friends','').split(',');
		var foes = GM_getValue('foes','').split(',');
		var other1 = GM_getValue('other1','').split(',');
		var other2 = GM_getValue('other2','').split(',');
		var imageusers = new Array(image.length);
		if(showImages == "true"){
			for(var i=0;i<image.length;i++){
				var defaultlist ='';
				if(i==0){//hey!
					defaultlist = fabulous;
				}
				if(i==8){//poop
					defaultlist='4'; //Steve Gibson
				}
				if(i==9){//star - Tv/Media Celebrity
				}
				if(i==10){//joystick 
					defaultlist = gamedeveloper;
				}
				if(i==11){//duke
					defaultlist = kickassnogum;
				}
				if(i==12){//greasemonkey
					defaultlist = greasemonkeydev;
				}
				var tempstr = GM_getValue('image'+i,defaultlist);
				if(tempstr==defaultlist)//without this, setting the first user to an icon that has a defaults would remove all the other users that had that icon as default.
					GM_setValue('image'+i,defaultlist);
				imageusers[i] = tempstr.split(',');
				//GM_log('Imageusers['+i+']='+imageusers[i]);
			}
		}
		
		var regex = /author_\d+/g
		//var regex = new RegExp('author_(\\d+)[ "]','g');
		//var regex = new RegExp('author_(\\d+)','g');


		var matches = (document.body.innerHTML).match(regex);

		//alert(matches.length);
		//alert(matches);
		var done = new Array();

		for(i=1;i<matches.length;i++){

			if(done[matches[i]]!=1){
			
				var id =  matches[i].split('_')[1];
				color = "000000" + id;
				color = color.substr(color.length-6);
				r = 255-((color.charAt(5)*20) + (color.charAt(2)*2));
				g = 255-((color.charAt(4)*20) + (color.charAt(1)*2));
				b = 255-((color.charAt(3)*20) + (color.charAt(0)*2));
				
				//alert("#"+matches[i]+"  "+color+"   "+r+","+g+","+b);
				if(hlThreadStarter == "true"){
					css += 'div.fpauthor_'+id+' + * + div.capcontainer div.olauthor_' + id + ' a.oneline_user {'
					css += threadstartercss;
					css += '}\n';
				
				}

				css += 'div.olauthor_' + id + ' a.oneline_user, .fpauthor_' + id + ' span.author>a:first-child { ';
				if(colorNames == "true"){
					css += 'color: rgb('+r+','+g+','+b+') !important; ';
				}
				if(showFriendFoe == "true"){
					if(friends.indexOf(id)>-1){
						css+= friendcss;
					}else if(foes.indexOf(id)>-1){
						css+= foecss;
					}else if(other1.indexOf(id)>-1){
						css+= other1css;
					}else if(other2.indexOf(id)>-1){
						css+= other2css;
					}
				}
				if(employees.indexOf(id)>-1 && showEmployees == "true"){
					css+= employeecss;
				}else if(mods.indexOf(id)>-1 && showMods == "true"){
					css+= modcss;
				}
				
				if(showImages == "true"){
					for(var j=0;j<image.length;j++){
						if(imageusers[j].indexOf(id)>-1){
							css+=' '+image[j];
						}
					}
				}
				
				css += '}\n';

				done[matches[i]]=1;
				count++;
			}
		}
	}else{
		if(showEmployees == "true"){
			for(var i=0;i<employees.length;i++){
				if(i>0) css+=', ';
				css += 'div.olauthor_' + employees[i] + ' a.oneline_user, .fpauthor_' + employees[i] + ' span.author>a:first-child\n';
			}
			css+= '{ '+employeecss+' }\n';
		}
		if(showMods == "true"){
			for(var i=0;i<mods.length;i++){
				if(i>0) css+=', ';
				css += 'div.olauthor_' + mods[i] + ' a.oneline_user, .fpauthor_' + mods[i] + ' span.author>a:first-child\n';
			}
			css+= '{ '+modcss+' }\n';
		}
		if(showFriendFoe == "true"){
			var friends = GM_getValue('friends','').split(',');
			var foes = GM_getValue('foes','').split(',');
			var other1 = GM_getValue('other1','').split(',');
			var other2 = GM_getValue('other2','').split(',');
			
			for(var i=0;i<friends.length;i++){
				if(i>0) css+=', ';
				css += 'div.olauthor_' + friends[i] + ' a.oneline_user, .fpauthor_' + friends[i] + ' span.author>a:first-child\n';
			}
			css+= '{ '+friendcss+' }\n';
		
			for(var i=0;i<foes.length;i++){
				if(i>0) css+=', ';
				css += 'div.olauthor_' + foes[i] + ' a.oneline_user, .fpauthor_' + foes[i] + ' span.author>a:first-child\n';
			}
			css+= '{ '+foecss+' }\n';
			
			for(var i=0;i<other1.length;i++){
				if(i>0) css+=', ';
				css += 'div.olauthor_' + other1[i] + ' a.oneline_user, .fpauthor_' + other1[i] + ' span.author>a:first-child\n';
			}
			css+= '{ '+other1css+' }\n';
			
			for(var i=0;i<other2.length;i++){
				if(i>0) css+=', ';
				css += 'div.olauthor_' + other2[i] + ' a.oneline_user, .fpauthor_' + other2[i] + ' span.author>a:first-child\n';
			}
			css+= '{ '+other2css+' }\n';
		
		}
		if(showImages == "true"){
			for(var i=0;i<image.length;i++){
				var defaultlist ='';
				if(i==0){//hey!
					defaultlist = fabulous;
				}
				if(i==8){//poop
					defaultlist='4'; //Steve Gibson
				}
				if(i==9){//star - Tv/Media Celebrity
				}
				if(i==10){//joystick 
					defaultlist = gamedeveloper;
				}
				if(i==11){//duke
					defaultlist = kickassnogum;
				}
				if(i==12){//greasemonkey
					defaultlist = greasemonkeydev;
				}
				var tempstr = GM_getValue('image'+i,defaultlist);
				if(tempstr==defaultlist)//without this, setting the first user to an icon that has a defaults would remove all the other users that had that icon as default.
					GM_setValue('image'+i,defaultlist);
				imageusers = tempstr.split(',');
				
				for(var j=0;j<imageusers.length;j++){
					if(j>0) css+=', ';
					css += 'div.olauthor_' + imageusers[j] + ' a.oneline_user, .fpauthor_' + imageusers[j] + ' span.author>a:first-child\n';
				}
				css+= '{ '+image[i]+' }\n';
			}
		}
	}

	//color your name
	if(highlightSelf == "true"){
		css+='div.oneline a.this_user:link, div.oneline a.this_user:visited, div.oneline a.this_user:active { '+highlightcss+' }';
	}

	GM_addStyle(css);

}else if(document.location.toString().indexOf("shacknews.com/settings/")>-1){

	//ok, now setup the config button
	var node = document.createElement("div");
	node.setAttribute('style','position: absolute; top: 22px; left: 30px; width: 20px; height: 20px; background: url("");');
	node.setAttribute('onclick','document.getElementById("ShacknewsNameColorFriendFoeSettings").style.display="block";');

	document.body.appendChild(node);

	//now setup the settings page
	node = document.createElement("div");
	node.setAttribute('id','ShacknewsNameColorFriendFoeSettings');
	node.setAttribute('style','position: absolute; top: 42px; left: 30px; border: 1px solid red; background: black; margin: 2px; padding: 2px; display: none; z-index: 10');
	var str;
	str='<table class="ShacknewsNameColorFriendFoeSettingsTable" style="padding: 2px; margin: 2px;">';
	
	str+='<tr><td>Color User Names:</td>';
	str+='<td><input id="ShacknewsNameColorFriendFoe_colorNames" type="checkbox" ';
	if(colorNames == "true") str+='checked';
	str+='></td></tr>';

	
	str+='<tr><td><span style="'+highlightcss+'">Highlight My Name</span>:</td>';
	str+='<td><input id="ShacknewsNameColorFriendFoe_highlightSelf" type="checkbox" ';
	if(highlightSelf == "true") str+='checked';
	str+='></td><td>CSS:<input type="text" size="100" id="ShacknewsNameColorFriendFoe_highlightcss" value="'+highlightcss+'">';
	str+='</td></tr>';
	
	str+='<tr><td><span style="'+threadstartercss+'">Highlight Thread Starter</span>:</td>';
	str+='<td><input id="ShacknewsNameColorFriendFoe_hlThreadStarter" type="checkbox" ';
	if(hlThreadStarter == "true") str+='checked';
	str+='></td><td>CSS:<input type="text" size="100" id="ShacknewsNameColorFriendFoe_threadstartercss" value="'+threadstartercss+'">';
	str+='</td></tr>';

	str+='<tr><td><span style="'+employeecss+'">Show Employees</span>:</td>';
	str+='<td><input id="ShacknewsNameColorFriendFoe_showEmployees" type="checkbox" ';
	if(showEmployees == "true") str+='checked';
	str+='></td><td>CSS:<input type="text" size="100" id="ShacknewsNameColorFriendFoe_employeecss" value="'+employeecss+'">';
	str+='</td></tr>';


	str+='<tr><td><span style="'+modcss+'">Show Mods</span>:</td>';
	str+='<td><input id="ShacknewsNameColorFriendFoe_showMods" type="checkbox" ';
	if(showMods == "true") str+='checked';
	str+='></td><td>CSS:<input type="text" size="100" id="ShacknewsNameColorFriendFoe_modcss" value="'+modcss+'">';
	str+='</td></tr>';


	str+='<tr><td>Show <span style="'+friendcss+'">Friends</span> / <span style="'+foecss+'">Foes</span> / <br><span style="'+other1css+'">Other 1</span> / <span style="'+other2css+'">Other 2</span>: </td>';
	str+='<td><input id="ShacknewsNameColorFriendFoe_showFriendFoe" type="checkbox" ';
	if(showFriendFoe == "true") str+='checked';
	str+='></td><td>CSS:<input type="text" size="45" id="ShacknewsNameColorFriendFoe_friendcss" value="'+friendcss+'">';
	str+=' / <input type="text" size="45" id="ShacknewsNameColorFriendFoe_foecss" value="'+foecss+'"> /<br>';
	str+='&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="text" size="45" id="ShacknewsNameColorFriendFoe_other1css" value="'+other1css+'">';
	str+=' / <input type="text" size="45" id="ShacknewsNameColorFriendFoe_other2css" value="'+other2css+'">';
	str+='</td></tr>';

	
	str+='<tr><td>Show User Images:</td>';
	str+='<td><input id="ShacknewsNameColorFriendFoe_showImages" type="checkbox" ';
	if(showImages == "true") str+='checked';
	str+='></td></tr>';
	
	str+='<tr><td>Show Menu on Mouse Over:</td>';
	str+='<td><input id="ShacknewsNameColorFriendFoe_menuMouseOver" type="checkbox" ';
	if(menuMouseOver == "true") str+='checked';
	str+='></td><td>(non-checked requires a click on a username to open the menu)</td></tr>';
	

	str+='</table><button onClick="';
	str+='document.getElementById(\'ShacknewsNameColorFriendFoeSettings\').style.display=\'none\';';
	str+='">Close</button>';
	node.innerHTML=str;

	GM_log(" 1");
	
	document.body.appendChild(node);
	

	GM_addStyle('table.ShacknewsNameColorFriendFoeSettingsTable,table.ShacknewsNameColorFriendFoeSettingsTable td{ border: none; padding: 2px;} table.ShacknewsNameColorFriendFoeSettingsTable input {background: #333333 !important;} ');

GM_log(" 2");	
	
	//add listeners to save states
	node = document.getElementById('ShacknewsNameColorFriendFoe_colorNames');
	if(node != null) node.addEventListener('change', saveSettingCheck, false);

	node = document.getElementById('ShacknewsNameColorFriendFoe_highlightSelf');
	if(node != null) node.addEventListener('change', saveSettingCheck, false);
	
	node = document.getElementById('ShacknewsNameColorFriendFoe_hlThreadStarter');
	if(node != null) node.addEventListener('change', saveSettingCheck, false);
	
	node = document.getElementById('ShacknewsNameColorFriendFoe_showEmployees');
	if(node != null) node.addEventListener('change', saveSettingCheck, false);
	
	node = document.getElementById('ShacknewsNameColorFriendFoe_showMods');
	if(node != null) node.addEventListener('change', saveSettingCheck, false);
	
	node = document.getElementById('ShacknewsNameColorFriendFoe_showFriendFoe');
	if(node != null) node.addEventListener('change', saveSettingCheck, false);
	
	node = document.getElementById('ShacknewsNameColorFriendFoe_showImages');
GM_log(" node = "+node);
	if(node != null) node.addEventListener('change', saveSettingCheck, false);
	
	node = document.getElementById('ShacknewsNameColorFriendFoe_menuMouseOver');
	if(node != null) node.addEventListener('change', saveSettingCheck, false);
	
	node = document.getElementById('ShacknewsNameColorFriendFoe_highlightcss');
	if(node != null) node.addEventListener('blur', saveSettingValue, false);
	
	node = document.getElementById('ShacknewsNameColorFriendFoe_threadstartercss');
	if(node != null) node.addEventListener('blur', saveSettingValue, false);
	
	node = document.getElementById('ShacknewsNameColorFriendFoe_employeecss');
	if(node != null) node.addEventListener('blur', saveSettingValue, false);
	
	node = document.getElementById('ShacknewsNameColorFriendFoe_modcss');
	if(node != null) node.addEventListener('blur', saveSettingValue, false);
	
	node = document.getElementById('ShacknewsNameColorFriendFoe_friendcss');
	if(node != null) node.addEventListener('blur', saveSettingValue, false);
	
	node = document.getElementById('ShacknewsNameColorFriendFoe_foecss');
	if(node != null) node.addEventListener('blur', saveSettingValue, false);
	
	node = document.getElementById('ShacknewsNameColorFriendFoe_other1css');
	if(node != null) node.addEventListener('blur', saveSettingValue, false);
	
	node = document.getElementById('ShacknewsNameColorFriendFoe_other2css');
	if(node != null) node.addEventListener('blur', saveSettingValue, false);

	GM_log(" 3");
}


if(menuMouseOver == "true"){
	window.addEventListener( 'mouseover', clickListener,true); //intercept clicks to the profile page
}else{
	window.addEventListener( 'click', clickListener,true); //intercept clicks to the profile page
}

   // log execution time
    tw_log('friendfoe.js: ' + location.href + ' / ' + (getTime() - scriptStartTime) + 'ms');
}